﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace XH.DigitaPlatform.Common.Converter
{
    public class RankingValueConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values == null || values.Length < 2)
            {
                // 如果输入值不足，返回默认值或抛出异常
                return Binding.DoNothing; // 或者返回一个默认值，比如 0.0
            }

            try
            {
                var value = double.Parse(values[0].ToString(), culture);
                var width = double.Parse(values[1].ToString(), culture);
                return value / 240 * width;
            }
            catch (FormatException ex)
            {
                // 处理格式异常，例如记录日志或显示错误信息
                Console.WriteLine($"FormatException: {ex.Message}");
                return Binding.DoNothing; // 或者返回一个默认值，比如 0.0
            }
            catch (OverflowException ex)
            {
                // 处理溢出异常，例如记录日志或显示错误信息
                Console.WriteLine($"OverflowException: {ex.Message}");
                return Binding.DoNothing; // 或者返回一个默认值，比如 0.0
            }
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}
